// JavaScript Document 

//DOJO SCRIPT
function getNews(ID,syndicated){
	
		dojo.xhrGet({
		        url: "fetchAjax.php?action=getStory&ID=" + ID + "&syndicated=" + syndicated,
		        handleAs: "text",
		        timeout: 5000, //Time in milliseconds
		        handle: function(response, ioArgs){
		                //This function handles the response.
		                //Inside this function, the "this" variable
		                //will be the object used as the argument to the dojo.xhrGet() call.
		                if(response instanceof Error){
		                        if(response.dojoType == "cancel"){
		                                //The request was canceled by some other JavaScript code.
		                                console.debug("Request canceled.");
		                        }else if(response.dojoType == "timeout"){
		                                //The request took over 5 seconds to complete.
		                                console.debug("Request timed out.");
		                        }else{
		                                //Some other error happened.
		                                console.error(response);
		                        }
		                }else{//successful query
		                
		                	//return data to page
		                	dojo.byId('previewDiv').innerHTML = response;
		                }
		                
						
		        }
		});	
	
	
	
	
}//end function







function displayMediaPlayer(soundFile,ID,flashID){
	var player = "<!--BEGIN MP3 PLAYER--><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='300' height='75' id='" + flashID + "' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='" + xoopsURL + "/modules/local_news/media/mp3Player.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><PARAM NAME=FlashVars VALUE='file="+ soundFile + "&autoPlayStart=true&flashID=" + flashID + "'><embed src='" + xoopsURL +"/modules/local_news/media/mp3Player.swf' FlashVars='file=" + soundFile +"&autoPlayStart=true&flashID=" + flashID + "' quality='high' swliveconnect='true' bgcolor='#ffffff' width='300' height='75' name='" + flashID + "' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object><!--END MP3 PLAYER-->";

	if(ID){
		dojo.byId(ID).innerHTML = player;
	}else{
		dojo.byId('soundClip').innerHTML = player;
	}
}



function addBody(ID,more){
	dojo.byId(more).style.visibility = 'hidden';
	//dojo.byId('spacer').style.display = 'none'; 
	dojo.byId(ID).style.display = 'block'; 
}



function popup(copyURL,newwidth,newheight){
    newwidth = newwidth + 15;
	newheight = newheight + 15;
    window.open(copyURL, 'newwin', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,width=' + newwidth + ',height=' + newheight);
};



function emailStory(ID,syndicated){
	popup('emailStory.php?ID='+ID+'&syndicated='+syndicated,450,325);
}



function printStory(ID,syndicated){
	popup('printStory.php?ID='+ID+'&syndicated='+syndicated,550,300);
}
 


//##############################
//FLASH MEDIA PLAYER FUNCTIONS 
//##############################

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return dojo.byId(movieName);
  }
}


function stopAllFlashPlayers(ID){
	
	if(ID != 'undefined' && window.lastID === undefined){
		lastID = ID;
	}else if(window.lastID !== undefined && window.lastID != ID){
		//alert('last ID x 2: ' + window.lastID + ' -- Current ID: '+ID);
		getFlashMovieObject(lastID).SetVariable("playBack", "stop"+window.lastID);
		window.lastID = ID;//set last playing movie to current movie for next time function is called
	}


} 